﻿var OperationInvoiceQuotaPricesLastPaxValue = 0;
var OperationInvoiceQtyValue = 0;
var RoomAutoComElem = null;
var RoomAutoComElemVal = null;
var RoomTimerId = null;
var isSearch = "False";
var isFilter = "False";
var LeftScrollPossition = 0;
var TopScrollPossition = 0;
var HotelPageNum = 1;
var isSaveOperationAmex = false;
var OperationClientSideHide = false;
var isBusSearch = "False";
var isBusFilter = "False";
var BusLeftScrollPossition = 0;
var BusTopScrollPossition = 0;
var BusPageNum = 1;
var BusisSaveOperationAmex = false;
var isAttractionsSearch = "False";
var isAttractionsFilter = "False";
var AttractionsLeftScrollPossition = 0;
var AttractionsTopScrollPossition = 0;
var AttractionsPageNum = 1;
var AttractionsisSaveOperationAmex = false;
var AttractionsisSelectOperationOptionalDetails = false;
var AttractionsisOperationOptionalDetailsPrice = 0;
var isMiscSearch = "False";
var isMiscFilter = "False";
var MiscLeftScrollPossition = 0;
var MiscTopScrollPossition = 0;
var MiscPageNum = 1;
var MiscisSaveOperationAmex = false;
var isGroupCheckListSearch = "False";
var isGroupCheckListFilter = "False";
var GroupCheckListLeftScrollPossition = 0;
var GroupCheckListTopScrollPossition = 0;
var GroupCheckListPageNum = 1;
var isTechProgSearch = "False";
var isTechProgFilter = "False";
var TechProgLeftScrollPossition = 0;
var TechProgTopScrollPossition = 0;
var IsHotelCompleted = false;
var IsBusCompleted = false;
var IsAttractionsCompleted = false;
var IsMiscCompleted = false;
var UpdateConfirms = false;
$(document).ready(function () {
    var path = window.location.pathname;
    if (path.indexOf("Operation") != -1) {
        $("#SideHeaderTabOperation").addClass("ActiveTab");
        $("#SideHeaderTabQuotation").removeClass("ActiveTab");
        if (UrlParam("Roomtab") == "Y") {
            var param = UrlParam("GroupCode");
            IsHotelCompleted = false;
            IsBusCompleted = false;
            IsAttractionsCompleted = false;
            IsMiscCompleted = false;
            LoadRoomGridByGroupCode(param);
            LoadHotelGridByGroupCode(param);
            LoadAttractionsGridByGroupCode(param);
            LoadMiscGridByGroupCode(param);
            LoadBusGridByGroupCode(param);
            LoadTechProgGridByGroupCode(param);
            LoadGroupCheckListGridByGroupCode(param);
        }
        else {
            InitOperationTabs();
        }
        $.validator.addMethod("OperationAmexDate", $.validator.methods.datePicker, Messages["OperationAmexDate"]);
        $.validator.addMethod("OperationAmexMaxLength50", $.validator.methods.maxlength, Messages["OperationAmexMaxLength50"]);
        $.validator.addMethod("OperationAmexMaxLength500", $.validator.methods.maxlength, Messages["OperationAmexMaxLength500"]);
        $.validator.addClassRules({
            Date: {
                OperationAmexDate: true,
            },
            MaxLength50: {
                OperationAmexMaxLength50: 50,
            },
            MaxLength500: {
                OperationAmexMaxLength500: 500,
            },
        });
        $('#LoadAmexVendorDetailsForm').validate();
    }
});
$(document).on('change', '.OperationAmexVendorElementChange', function () {
    $("#OperationAmexVendorDetailsSaveBtn").addClass("QuotaDetDataChanged")
});
function InitOperationTabs()
{
    // hotel
    LoadHotelGrid();
    LoadRoomGrid();
    LoadBusGrid();
    LoadInvoice();
    LoadAttractionsGrid();
    LoadMiscGrid();
    LoadTechProgGrid();
    LoadGroupCheckListGrid();
}

$(document).on('click', '.OperationTabs', function () {
    var ElemId = $(this).attr("href");
    if ($("#OperHotelSaveBtn").hasClass("GridDataChanged") && ElemId != "#tabHotels")
        jAlert('There is/are unsaved data in Hotels tab.', 'Attention!');
    if ($("#OperRoomSaveBtn").hasClass("GridDataChanged") && ElemId != "#tabRooms")
        jAlert('There is/are unsaved data in Rooms tab.', 'Attention!');
    if ($("#OperAttractionsSaveBtn").hasClass("GridDataChanged") && ElemId != "#tabAttractions")
        jAlert('There is/are unsaved data in Attractions tab.', 'Attention!');
    if ($("#OperMiscSaveBtn").hasClass("GridDataChanged") && ElemId != "#tabMisc")
        jAlert('There is/are unsaved data in Misc tab.', 'Attention!');
    if ($("#OperBusSaveBtn").hasClass("GridDataChanged") && ElemId != "#tabBus")
        jAlert('There is/are unsaved data in Bus tab.', 'Attention!');
    if (($("#operVendConfsavebtn").hasClass("GridDataChanged") || $("#OperVendorRoomSaveBtn").hasClass("GridDataChanged")) && ElemId != "#tabVendorConfirm")
        jAlert('There is/are unsaved data in VendorConfirm tab.', 'Attention!');
    if ($("#OperInvSaveBtn").hasClass("GridDataChanged") && ElemId != "#tabInvoice")
        jAlert('There is/are unsaved data in Invoice tab.', 'Attention!');
    if ($("#TechProgSaveBtn").hasClass("GridDataChanged") && ElemId != "#tabTechProg")
        jAlert('There is/are unsaved data in TechProg tab.', 'Attention!');
    if ($("#GroupCheckListGridUpdate").hasClass("GridDataChanged") && ElemId != "#tabGroupCheckList")
        jAlert('There is/are unsaved data in GroupCheckList tab.', 'Attention!');
});
$(document).on('click', '.VcnfTabs', function () {
    var ElemId = $(this).attr("href");
    if ($("#operVendConfsavebtn").hasClass("GridDataChanged") && ElemId != "#tabConfirmation")
        jAlert('There is/are unsaved data in Confirmation tab.', 'Attention!');
    if ($("#OperVendorRoomSaveBtn").hasClass("GridDataChanged") && ElemId != "#tabRoomingList")
        jAlert('There is/are unsaved data in Rooming List tab.', 'Attention!');
});
// hotel search calendars
function InitHotelSearchCalendars() {
    $("#SearchCheckInFromDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'D, dd/M/yy',
        onClose: function (selectedDate) {
            $("#SearchCheckInToDate").datepicker("option", "minDate", selectedDate);
        },
        beforeShow:function(input) {
            $(input).css({
                "z-index": 999999
            });
        }
    });
    $("#SearchCheckInToDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'D, dd/M/yy',
        onClose: function (selectedDate) {
            $(".SearchCheckInFromDate").datepicker("option", "maxDate", selectedDate);
        },
        beforeShow: function (input) {
            $(input).css({
                "z-index": 999999
            });
        }
    });
    $("#SearchCheckOutFromDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'D, dd/M/yy',
        onClose: function (selectedDate) {
            $("#SearchCheckOutToDate").datepicker("option", "minDate", selectedDate);
        },
        beforeShow: function (input) {
            $(input).css({
                "z-index": 999999
            });
        }
    });
    $("#SearchCheckOutToDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'D, dd/M/yy',
        onClose: function (selectedDate) {
            $(".SearchCheckOutFromDate").datepicker("option", "maxDate", selectedDate);
        },
        beforeShow: function (input) {
            $(input).css({
                "z-index": 999999
            });
        }
    });

}
// Attractions search calendars
function InitAttractionsSearchCalendars() {
    $("#AttractionsSearchStartFromDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 999999,
            });
        },
        onClose: function (selectedDate) {
            $("#AttractionsSearchStartToDate").datepicker("option", "minDate", selectedDate);
        }
    });
    $("#AttractionsSearchStartToDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 999999,
            });
        },
        onClose: function (selectedDate) {
            $("#AttractionsSearchStartFromDate").datepicker("option", "maxDate", selectedDate);
        }
    });
}
// Misc search calendars
function InitMiscSearchCalendars() {
    $("#MiscSearchStartFromDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 999999,
            });
        },
        onClose: function (selectedDate) {
            $("#MiscSearchStartToDate").datepicker("option", "minDate", selectedDate);
        }
    });
    $("#MiscSearchStartToDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 999999,
            });
        },
        onClose: function (selectedDate) {
            $("#MiscSearchStartFromDate").datepicker("option", "maxDate", selectedDate);
        }
    });
}
// Bus search calendars
function InitBusSearchCalendars() {
    $("#BusSearchStartFromDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 999999,
            });
        },
        onClose: function (selectedDate) {
            $("#BusSearchStartToDate").datepicker("option", "minDate", selectedDate);
        }
    });
    $("#BusSearchStartToDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 999999,
            });
        },
        onClose: function (selectedDate) {
            $("#BusSearchStartFromDate").datepicker("option", "maxDate", selectedDate);
        }
    });
}
//TechProg Group Search
function OperTechProgSearch() {
    $("#TechProgIsSearch").val("True");
    TechProgLeftScrollPossition = $("#OperTechProgGrid").scrollLeft();
    $("#TechProgLeftScrollPossition").val(TechProgLeftScrollPossition);
    isTechProgSearch = "True";
    $("#TechProgGridUpdate").click();
}
// TechProg Filtering
$(document).on('click', '.TechProgGridFilterBtn', function () {
    TechProgLeftScrollPossition = $("#OperTechProgGrid").scrollLeft();
    $("#TechProgLeftScrollPossition").val(TechProgLeftScrollPossition);
    var ElemId = $(this).attr("id");
    var parDiv = $(this).parent().parent().parent();
    var width = parDiv.width();
    var position = parDiv.offset();
    position.top = position.top + parDiv.height() + 2;
    $("#" + ElemId + "MainDiv").offset({ top: position.top, left: position.left });
    $("#" + ElemId + "MainDiv").width(width - 3);
    if ($("#" + ElemId + "MainDiv").is(":visible")) {
        $("#" + ElemId + "MainDiv").hide();
        $("#IsTechProgFilter").val("True");
        isTechProgFilter = "True";
        $("#TechProgGridUpdate").click();
    }
    else
        $("#" + ElemId + "MainDiv").show();
});
// hide filter div when clicked on div 
$(document).on('click', '.TechProgGridFilterDivClose', function () {
    $(this).parent().offset({ left: 0, top: 0 }).css({
        'display': 'none'
    });
});
function TechProgGridAjaxComplated() {
    if ($("#TechProgLeftScrollPossition").val() != "") {
        $("#OperTechProgGrid").scrollLeft(parseFloat($("#TechProgLeftScrollPossition").val()));
    }
    if ($("#TechProgTopScrollPossition").val() != "") {
        $("#OperTechProgGrid").scrollTop(parseFloat($("#TechProgTopScrollPossition").val()));
    }
}


//GroupCheckList Group Search
function GroupCheckListGroupSearchBtnClick() {
    $("#IsGroupCheckListSearch").val("True");
    GroupCheckListLeftScrollPossition = $("#OperGroupCheckListGrid").scrollLeft();
    $("#GroupCheckListLeftScrollPossition").val(GroupCheckListLeftScrollPossition);
    isGroupCheckListSearch = "True";
    $("#GroupCheckListGridUpdate").click();
}
// GroupCheckList More
function GroupCheckListMoreBtnClick() {
    $("#IsGroupCheckListSearch").val(isGroupCheckListSearch);
    $("#IsGroupCheckListFilter").val(isGroupCheckListFilter);
    GroupCheckListLeftScrollPossition = $("#OperGroupCheckListGrid").scrollLeft();
    $("#GroupCheckListLeftScrollPossition").val(GroupCheckListLeftScrollPossition);
    GroupCheckListTopScrollPossition = $("#OperGroupCheckListGrid").scrollTop();
    $("#GroupCheckListTopScrollPossition").val(GroupCheckListTopScrollPossition);
    if ($("#IsGroupCheckListSearch").val() != "True" && $("#IsGroupCheckListFilter").val() != "True") {
        $("#IsGroupCheckListView").val("True");
    }
    else {
        $("#IsGroupCheckListView").val("False");
    }
    GroupCheckListPageNum = GroupCheckListPageNum + 1;
    $("#GroupCheckListPageNumber").val(GroupCheckListPageNum.toString());
    $("#GroupCheckListGridUpdate").click();
}
// GroupCheckList Filtering
$(document).on('click', '.GroupCheckListGridFilterBtn', function () {
    GroupCheckListLeftScrollPossition = $("#OperGroupCheckListGrid").scrollLeft();
    $("#GroupCheckListLeftScrollPossition").val(GroupCheckListLeftScrollPossition);
    var ElemId = $(this).attr("id");
    var parDiv = $(this).parent().parent().parent();
    var width = parDiv.width();
    var position = parDiv.offset();
    position.top = position.top + parDiv.height() + 2;
    $("#" + ElemId + "MainDiv").offset({ top: position.top, left: position.left });
    $("#" + ElemId + "MainDiv").width(width - 3);
    if ($("#" + ElemId + "MainDiv").is(":visible")) {
        $("#" + ElemId + "MainDiv").hide();
        $("#IsGroupCheckListFilter").val("True");
        isGroupCheckListFilter = "True";
        $("#GroupCheckListGridUpdate").click();
    }
    else
        $("#" + ElemId + "MainDiv").show();
});

// hide filter div when clicked on div 
$(document).on('click', '.GroupCheckListGridFilterDivClose', function () {
    $(this).parent().offset({ left: 0, top: 0 }).css({
        'display': 'none'
    });
});
function GroupCheckListGridAjaxComplated() {
    if ($("#GroupCheckListLeftScrollPossition").val() != "") {
        $("#OperGroupCheckListGrid").scrollLeft(parseFloat($("#GroupCheckListLeftScrollPossition").val()));
    }
    if ($("#GroupCheckListTopScrollPossition").val() != "") {
        $("#OperGroupCheckListGrid").scrollTop(parseFloat($("#GroupCheckListTopScrollPossition").val()));
    }
    //InitGroupCheckListSearchCalendars();
}
//Attractions Group Search
function AttractionsGroupSearchBtnClick() {
    $("#AttractionsPageNumber").val(1);
    AttractionsPageNum = 1;
    $("#IsAttractionsSearch").val("True");
    AttractionsLeftScrollPossition = $("#OperAttractionsGrid").scrollLeft();
    $("#AttractionsLeftScrollPossition").val(AttractionsLeftScrollPossition);
    isAttractionsSearch = "True";
    $("#AttractionsGridUpdate").click();
}
// Attractions Prev
function AttractionsPrevBtnClick() {
    $("#IsAttractionsSearch").val(isAttractionsSearch);
    $("#IsAttractionsFilter").val(isAttractionsFilter);
    AttractionsLeftScrollPossition = $("#OperAttractionsGrid").scrollLeft();
    $("#AttractionsLeftScrollPossition").val(AttractionsLeftScrollPossition);
    AttractionsTopScrollPossition = $("#OperAttractionsGrid").scrollTop();
    $("#AttractionsTopScrollPossition").val(AttractionsTopScrollPossition);
    if ($("#IsAttractionsSearch").val() != "True" && $("#IsAttractionsFilter").val() != "True") {
        $("#IsAttractionsView").val("True");
    }
    else {
        $("#IsAttractionsView").val("False");
    }
    AttractionsPageNum = AttractionsPageNum - 1;
    $("#AttractionsPageNumber").val(AttractionsPageNum.toString());
    $("#AttractionsGridUpdate").click();
}
// Attractions Next
function AttractionsNextBtnClick() {
    $("#IsAttractionsSearch").val(isAttractionsSearch);
    $("#IsAttractionsFilter").val(isAttractionsFilter);
    AttractionsLeftScrollPossition = $("#OperAttractionsGrid").scrollLeft();
    $("#AttractionsLeftScrollPossition").val(AttractionsLeftScrollPossition);
    AttractionsTopScrollPossition = $("#OperAttractionsGrid").scrollTop();
    $("#AttractionsTopScrollPossition").val(AttractionsTopScrollPossition);
    if ($("#IsAttractionsSearch").val() != "True" && $("#IsAttractionsFilter").val() != "True") {
        $("#IsAttractionsView").val("True");
    }
    else {
        $("#IsAttractionsView").val("False");
    }
    AttractionsPageNum = AttractionsPageNum + 1;
    $("#AttractionsPageNumber").val(AttractionsPageNum.toString());
    $("#AttractionsGridUpdate").click();
}
// Attractions Filtering
$(document).on('click', '.AttractionsGridFilterBtn', function () {
    $("#AttractionsPageNumber").val(1);
    AttractionsPageNum = 1;
    AttractionsLeftScrollPossition = $("#OperAttractionsGrid").scrollLeft();
    $("#AttractionsLeftScrollPossition").val(AttractionsLeftScrollPossition);
    var ElemId = $(this).attr("id");
    var parDiv = $(this).parent().parent().parent();
    var width = parDiv.width();
    var position = parDiv.offset();
    position.top = position.top + parDiv.height() + 2;
    $("#" + ElemId + "MainDiv").offset({ top: position.top, left: position.left });
    $("#" + ElemId + "MainDiv").width(width - 3);
    if ($("#" + ElemId + "MainDiv").is(":visible")) {
        $("#" + ElemId + "MainDiv").hide();
        $("#IsAttractionsFilter").val("True");
        isAttractionsFilter = "True";
        $("#AttractionsGridUpdate").click();
    }
    else
        $("#" + ElemId + "MainDiv").show();
});

// hide filter div when clicked on div 
$(document).on('click', '.AttractionsGridFilterDivClose', function () {
    $(this).parent().offset({ left: 0, top: 0 }).css({
        'display': 'none'
    });
});
function AttractionsGridAjaxCompleted() {
    if ($("#AttractionsLeftScrollPossition").val() != "") {
        $("#OperAttractionsGrid").scrollLeft(parseFloat($("#AttractionsLeftScrollPossition").val()));
    }
    if ($("#AttractionsTopScrollPossition").val() != "") {
        $("#OperAttractionsGrid").scrollTop(parseFloat($("#AttractionsTopScrollPossition").val()));
    }
    InitAttractionsSearchCalendars();
    UpdateGrpProfits();
}
//Misc Group Search
function MiscGroupSearchBtnClick() {
    $("#MiscPageNumber").val(1);
    MiscPageNum = 1;
    $("#IsMiscSearch").val("True");
    MiscLeftScrollPossition = $("#OperMiscGrid").scrollLeft();
    $("#MiscLeftScrollPossition").val(MiscLeftScrollPossition);
    isMiscSearch = "True";
    $("#MiscGridUpdate").click();
}
// Misc Next
function MiscNextBtnClick() {
    $("#IsMiscSearch").val(isMiscSearch);
    $("#IsMiscFilter").val(isMiscFilter);
    MiscLeftScrollPossition = $("#OperMiscGrid").scrollLeft();
    $("#MiscLeftScrollPossition").val(MiscLeftScrollPossition);
    MiscTopScrollPossition = $("#OperMiscGrid").scrollTop();
    $("#MiscTopScrollPossition").val(MiscTopScrollPossition);
    if ($("#IsMiscSearch").val() != "True" && $("#IsMiscFilter").val() != "True") {
        $("#IsMiscView").val("True");
    }
    else {
        $("#IsMiscView").val("False");
    }
    MiscPageNum = MiscPageNum + 1;
    $("#MiscPageNumber").val(MiscPageNum.toString());
    $("#MiscGridUpdate").click();
}
// Misc Prev
function MiscPrevBtnClick() {
    $("#IsMiscSearch").val(isMiscSearch);
    $("#IsMiscFilter").val(isMiscFilter);
    MiscLeftScrollPossition = $("#OperMiscGrid").scrollLeft();
    $("#MiscLeftScrollPossition").val(MiscLeftScrollPossition);
    MiscTopScrollPossition = $("#OperMiscGrid").scrollTop();
    $("#MiscTopScrollPossition").val(MiscTopScrollPossition);
    if ($("#IsMiscSearch").val() != "True" && $("#IsMiscFilter").val() != "True") {
        $("#IsMiscView").val("True");
    }
    else {
        $("#IsMiscView").val("False");
    }
    MiscPageNum = MiscPageNum - 1;
    $("#MiscPageNumber").val(MiscPageNum.toString());
    $("#MiscGridUpdate").click();
}
// Misc Filtering
$(document).on('click', '.MiscGridFilterBtn', function () {
    $("#MiscPageNumber").val(1);
    MiscPageNum = 1;
    MiscLeftScrollPossition = $("#OperMiscGrid").scrollLeft();
    $("#MiscLeftScrollPossition").val(MiscLeftScrollPossition);
    var ElemId = $(this).attr("id");
    var parDiv = $(this).parent().parent().parent();
    var width = parDiv.width();
    var position = parDiv.offset();
    position.top = position.top + parDiv.height() + 2;
    $("#" + ElemId + "MainDiv").offset({ top: position.top, left: position.left });
    $("#" + ElemId + "MainDiv").width(width - 3);
    if ($("#" + ElemId + "MainDiv").is(":visible")) {
        $("#" + ElemId + "MainDiv").hide();
        $("#IsMiscFilter").val("True");
        isMiscFilter = "True";
        $("#MiscGridUpdate").click();
    }
    else
        $("#" + ElemId + "MainDiv").show();
});

// hide filter div when clicked on div 
$(document).on('click', '.MiscGridFilterDivClose', function () {
    $(this).parent().offset({ left: 0, top: 0 }).css({
        'display': 'none'
    });
});
function MiscGridAjaxCompleted() {
    if ($("#MiscLeftScrollPossition").val() != "") {
        $("#OperMiscGrid").scrollLeft(parseFloat($("#MiscLeftScrollPossition").val()));
    }
    if ($("#MiscTopScrollPossition").val() != "") {
        $("#OperMiscGrid").scrollTop(parseFloat($("#MiscTopScrollPossition").val()));
    }
    InitMiscSearchCalendars();
    UpdateGrpProfits();
}
//Bus Group Search
function BusGroupSearchBtnClick() {
    $("#BusPageNumber").val(1);
    BusPageNum = 1;
    $("#IsBusSearch").val("True");
    BusLeftScrollPossition = $("#OperBusGrid").scrollLeft();
    $("#BusLeftScrollPossition").val(BusLeftScrollPossition);
    isBusSearch = "True";
    $("#BusGridUpdate").click();
}
// Bus Prev
function BusPrevBtnClick() {
    $("#IsBusSearch").val(isBusSearch);
    $("#IsBusFilter").val(isBusFilter);
    BusLeftScrollPossition = $("#OperBusGrid").scrollLeft();
    $("#BusLeftScrollPossition").val(BusLeftScrollPossition);
    BusTopScrollPossition = $("#OperBusGrid").scrollTop();
    $("#BusTopScrollPossition").val(BusTopScrollPossition);
    if ($("#IsBusSearch").val() != "True" && $("#IsBusFilter").val() != "True") {
        $("#IsBusView").val("True");
    }
    else {
        $("#IsBusView").val("False");
    }
    BusPageNum = BusPageNum - 1;
    $("#BusPageNumber").val(BusPageNum.toString());
    $("#BusGridUpdate").click();
}
// Bus Next
function BusNextBtnClick() {
    $("#IsBusSearch").val(isBusSearch);
    $("#IsBusFilter").val(isBusFilter);
    BusLeftScrollPossition = $("#OperBusGrid").scrollLeft();
    $("#BusLeftScrollPossition").val(BusLeftScrollPossition);
    BusTopScrollPossition = $("#OperBusGrid").scrollTop();
    $("#BusTopScrollPossition").val(BusTopScrollPossition);
    if ($("#IsBusSearch").val() != "True" && $("#IsBusFilter").val() != "True") {
        $("#IsBusView").val("True");
    }
    else {
        $("#IsBusView").val("False");
    }
    BusPageNum = BusPageNum + 1;
    $("#BusPageNumber").val(BusPageNum.toString());
    $("#BusGridUpdate").click();
}
// Bus Filtering
$(document).on('click', '.BusGridFilterBtn', function () {
    $("#BusPageNumber").val(1);
    BusPageNum = 1;
    BusLeftScrollPossition = $("#OperBusGrid").scrollLeft();
    $("#BusLeftScrollPossition").val(BusLeftScrollPossition);
    var ElemId = $(this).attr("id");
    var parDiv = $(this).parent().parent().parent();
    var width = parDiv.width();
    var position = parDiv.offset();
    position.top = position.top + parDiv.height() + 2;
    $("#" + ElemId + "MainDiv").offset({ top: position.top, left: position.left });
    $("#" + ElemId + "MainDiv").width(width - 3);
    if ($("#" + ElemId + "MainDiv").is(":visible")) {
        $("#" + ElemId + "MainDiv").hide();
        $("#IsBusFilter").val("True");
        isBusFilter = "True";
        $("#BusGridUpdate").click();
    }
    else
        $("#" + ElemId + "MainDiv").show();
});

// hide filter div when clicked on div 
$(document).on('click', '.BusGridFilterDivClose', function () {
    $(this).parent().offset({ left: 0, top: 0 }).css({
        'display': 'none'
    });
});
function BusGridAjaxCompleted() {
    if ($("#BusLeftScrollPossition").val() != "") {
        $("#OperBusGrid").scrollLeft(parseFloat($("#BusLeftScrollPossition").val()));
    }
    if ($("#BusTopScrollPossition").val() != "") {
        $("#OperBusGrid").scrollTop(parseFloat($("#BusTopScrollPossition").val()));
    }
    InitBusSearchCalendars();
    UpdateGrpProfits();
}
// Hotel Group Search
function GroupSearchBtnClick()
{
    $("#HotelPageNumber").val(1);
    HotelPageNum = 1;
    $("#IsSearch").val("True");
    LeftScrollPossition = $("#OperHotelGrid").scrollLeft();
    $("#LeftScrollPossition").val(LeftScrollPossition);
    isSearch = "True";
    $("#HotelGridUpdate").click();
}
// Hotel Next
function HotelNextBtnClick() {
    $("#IsSearch").val(isSearch);
    $("#IsFilter").val(isFilter);
    LeftScrollPossition = $("#OperHotelGrid").scrollLeft();
    $("#LeftScrollPossition").val(LeftScrollPossition);
    TopScrollPossition = $("#OperHotelGrid").scrollTop();
    $("#TopScrollPossition").val(TopScrollPossition);
    if ($("#IsSearch").val() != "True" && $("#IsFilter").val() != "True") {
        $("#IsView").val("True");
    }
    else {
        $("#IsView").val("False");
    }
    HotelPageNum = HotelPageNum + 1;
    $("#HotelPageNumber").val(HotelPageNum.toString());
    $("#HotelGridUpdate").click();
}
// Hotel Prev
function HotelPrevBtnClick() {
    $("#IsSearch").val(isSearch);
    $("#IsFilter").val(isFilter);
    LeftScrollPossition = $("#OperHotelGrid").scrollLeft();
    $("#LeftScrollPossition").val(LeftScrollPossition);
    TopScrollPossition = $("#OperHotelGrid").scrollTop();
    $("#TopScrollPossition").val(TopScrollPossition);
    if ($("#IsSearch").val() != "True" && $("#IsFilter").val() != "True")
    {
        $("#IsView").val("True");
    }
    else
    {
        $("#IsView").val("False");
    }
    HotelPageNum = HotelPageNum - 1;
    $("#HotelPageNumber").val(HotelPageNum.toString());
    $("#HotelGridUpdate").click();
}
// Filtering
$(document).on('click', '.HotelGridFilterBtn', function () {
    $("#HotelPageNumber").val(1);
    HotelPageNum = 1;
    LeftScrollPossition = $("#OperHotelGrid").scrollLeft();
    $("#LeftScrollPossition").val(LeftScrollPossition);
    var ElemId = $(this).attr("id");
    var parDiv = $(this).parent().parent().parent();
    var width = parDiv.width();
    var position = parDiv.offset();
    position.top = position.top + parDiv.height() + 2;
    $("#" + ElemId + "MainDiv").offset({ top: position.top, left: position.left });
    $("#" + ElemId + "MainDiv").width(width - 3);
    if ($("#" + ElemId + "MainDiv").is(":visible")) {
        $("#" + ElemId + "MainDiv").hide();
        $("#IsFilter").val("True");
        isFilter = "True";
        $("#HotelGridUpdate").click();
    }
    else
        $("#" + ElemId + "MainDiv").show();
});

// hide filter div when clicked on div 
$(document).on('click', '.HotelGridFilterDivClose', function () {
    $(this).parent().offset({ left: 0, top: 0 }).css({
        'display': 'none'
    });
});

function LoadHotelGrid()
{
    // Hotels
    $.ajax({
        url: urls["LoadOperationHotelsTab"],
        contentType: 'application/json; charset=utf-8',
        data: $('#OperHotelGridForm').serialize(),
        type: 'POST',
        success: function (data) {
            $("#tabHotels").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            //  $("#LoadingDiv").hide();
            // $("#Tabs").show();
            InitHotelSearchCalendars();
        }
    });
}
function UpdateGrpProfits()
{
    if(IsHotelCompleted && IsBusCompleted && IsAttractionsCompleted && IsMiscCompleted)
    {
        var TotInv = $("#TotInv").val();
        var TotInvCad = $("#TotInvCad").val();
        var TotHotelCost = $("#TotCost").val();
        var TotHotelCostCad = $("#TotCostCad").val();
        var TotAttractionCost = $("#AttractionsTotCost").val();
        var TotAttractionCostCad = $("#AttractionsTotCostCad").val();
        var TotMiscCost = $("#MiscTotCost").val();
        var TotMiscCostCad = $("#MiscTotCostCad").val();
        var TotBusCost = $("#BusTotCost").val();
        var TotBusCostCad = $("#BusTotCostCad").val();
        var GroupProfit = TotInv - TotHotelCost - TotAttractionCost - TotMiscCost - TotBusCost;
        var GroupProfitCad = TotInvCad - TotHotelCostCad - TotAttractionCostCad - TotMiscCostCad - TotBusCostCad;
        var GroupProfitPerc = (TotInv == 0 ? 0 : 100 * (GroupProfit / TotInv));
        var GroupProfitPercCad = (TotInvCad == 0 ? 0 : 100 * (GroupProfitCad / TotInvCad));

        if ($("#AttractionsTotInv").length > 0 && $("#AttractionsTotInvCAD").length > 0
            && $("#AttractionsGroupProfit").length > 0 && $("#AttractionsGroupProfitCad").length > 0
            && $("#AttractionsProfitPers").length > 0 && $("#AttractionsProfitPersCAD").length > 0)
        {
            $("#AttractionsTotInv").text(parseFloat(TotInv).toFixed(2).toString() + " USD")
            if (TotInv < 0) {
                $("#AttractionsTotInv").addClass('SumControls10Size');
            }
            else {
                $("#AttractionsTotInv").addClass('SumControls10Sizeblack');
            }
            $("#AttractionsTotInvCAD").text(parseFloat(TotInvCad).toFixed(2).toString() + " CAD")
            if (TotInvCad < 0) {
                $("#AttractionsTotInvCAD").addClass('SumControls10Size');
            }
            else {
                $("#AttractionsTotInvCAD").addClass('SumControls10Sizeblack');
            }
            $("#AttractionsGroupProfit").text(GroupProfit.toFixed(2).toString() + " USD")
            if (GroupProfit < 0) {
                $("#AttractionsGroupProfit").addClass('SumControls10Size');
            }
            else {
                $("#AttractionsGroupProfit").addClass('SumControls10Sizeblack');
            }
            $("#AttractionsGroupProfitCad").text(GroupProfitCad.toFixed(2).toString() + " CAD")
            if (GroupProfitCad < 0) {
                $("#AttractionsGroupProfitCad").addClass('SumControls10Size');
            }
            else {
                $("#AttractionsGroupProfitCad").addClass('SumControls10Sizeblack');
            }
            $("#AttractionsProfitPers").text(GroupProfitPerc.toFixed(2).toString() + " %")
            if (GroupProfitPerc < 0) {
                $("#AttractionsProfitPers").addClass('SumControls10Size');
            }
            else {
                $("#AttractionsProfitPers").addClass('SumControls10Sizeblack');
            }
            $("#AttractionsProfitPersCAD").text(GroupProfitPercCad.toFixed(2).toString() + " %")
            if (GroupProfitPercCad < 0) {
                $("#AttractionsProfitPersCAD").addClass('SumControls10Size');
            }
            else {
                $("#AttractionsProfitPersCAD").addClass('SumControls10Sizeblack');
            }
        }
        if ($("#MiscTotInv").length > 0 && $("#MiscTotInvCAD").length > 0
            && $("#MiscGroupProfit").length > 0 && $("#MiscGroupProfitCad").length > 0
            && $("#MiscProfitPers").length > 0 && $("#MiscProfitPersCAD").length > 0) {
            $("#MiscTotInv").text(parseFloat(TotInv).toFixed(2).toString() + " USD")
            if (TotInv < 0) {
                $("#MiscTotInv").addClass('SumControls10Size');
            }
            else {
                $("#MiscTotInv").addClass('SumControls10Sizeblack');
            }
            $("#MiscTotInvCAD").text(parseFloat(TotInvCad).toFixed(2).toString() + " CAD")
            if (TotInvCad < 0) {
                $("#MiscTotInvCAD").addClass('SumControls10Size');
            }
            else {
                $("#MiscTotInvCAD").addClass('SumControls10Sizeblack');
            }
            $("#MiscGroupProfit").text(GroupProfit.toFixed(2).toString() + " USD")
            if (GroupProfit < 0) {
                $("#MiscGroupProfit").addClass('SumControls10Size');
            }
            else {
                $("#MiscGroupProfit").addClass('SumControls10Sizeblack');
            }
            $("#MiscGroupProfitCad").text(GroupProfitCad.toFixed(2).toString() + " CAD")
            if (GroupProfitCad < 0) {
                $("#MiscGroupProfitCad").addClass('SumControls10Size');
            }
            else {
                $("#MiscGroupProfitCad").addClass('SumControls10Sizeblack');
            }
            $("#MiscProfitPers").text(GroupProfitPerc.toFixed(2).toString() + " %")
            if (GroupProfitPerc < 0) {
                $("#MiscProfitPers").addClass('SumControls10Size');
            }
            else {
                $("#MiscProfitPers").addClass('SumControls10Sizeblack');
            }
            $("#MiscProfitPersCAD").text(GroupProfitPercCad.toFixed(2).toString() + " %")
            if (GroupProfitPercCad < 0) {
                $("#MiscProfitPersCAD").addClass('SumControls10Size');
            }
            else {
                $("#MiscProfitPersCAD").addClass('SumControls10Sizeblack');
            }
        }
        if ($("#BusTotInv").length > 0 && $("#BusTotInvCAD").length > 0
            && $("#BusGroupProfit").length > 0 && $("#BusGroupProfitCad").length > 0
            && $("#BusProfitPers").length > 0 && $("#BusProfitPersCAD").length > 0) {
            $("#BusTotInv").text(parseFloat(TotInv).toFixed(2).toString() + " USD")
            if (TotInv < 0) {
                $("#BusTotInv").addClass('SumControls10Size');
            }
            else {
                $("#BusTotInv").addClass('SumControls10Sizeblack');
            }
            $("#BusTotInvCAD").text(parseFloat(TotInvCad).toFixed(2).toString() + " CAD")
            if (TotInvCad < 0) {
                $("#BusTotInvCAD").addClass('SumControls10Size');
            }
            else {
                $("#BusTotInvCAD").addClass('SumControls10Sizeblack');
            }
            $("#BusGroupProfit").text(GroupProfit.toFixed(2).toString() + " USD")
            if (GroupProfit < 0) {
                $("#BusGroupProfit").addClass('SumControls10Size');
            }
            else {
                $("#BusGroupProfit").addClass('SumControls10Sizeblack');
            }
            $("#BusGroupProfitCad").text(GroupProfitCad.toFixed(2).toString() + " CAD")
            if (GroupProfitCad < 0) {
                $("#BusGroupProfitCad").addClass('SumControls10Size');
            }
            else {
                $("#BusGroupProfitCad").addClass('SumControls10Sizeblack');
            }
            $("#BusProfitPers").text(GroupProfitPerc.toFixed(2).toString() + " %")
            if (GroupProfitPerc < 0) {
                $("#BusProfitPers").addClass('SumControls10Size');
            }
            else {
                $("#BusProfitPers").addClass('SumControls10Sizeblack');
            }
            $("#BusProfitPersCAD").text(GroupProfitPercCad.toFixed(2).toString() + " %")
            if (GroupProfitPercCad < 0) {
                $("#BusProfitPersCAD").addClass('SumControls10Size');
            }
            else {
                $("#BusProfitPersCAD").addClass('SumControls10Sizeblack');
            }
        }
        if ($("#HotelGroupProfit").length > 0 && $("#HotelGroupProfitCad").length > 0
            && $("#HotelProfitPers").length > 0 && $("#HotelProfitPersCAD").length > 0) {
            $("#HotelGroupProfit").text(GroupProfit.toFixed(2).toString() + " USD")
            if (GroupProfit < 0) {
                $("#HotelGroupProfit").addClass('SumControls10Size');
            }
            else {
                $("#HotelGroupProfit").addClass('SumControls10Sizeblack');
            }
            $("#HotelGroupProfitCad").text(GroupProfitCad.toFixed(2).toString() + " CAD")
            if (GroupProfitCad < 0) {
                $("#HotelGroupProfitCad").addClass('SumControls10Size');
            }
            else {
                $("#HotelGroupProfitCad").addClass('SumControls10Sizeblack');
            }
            $("#HotelProfitPers").text(GroupProfitPerc.toFixed(2).toString() + " %")
            if (GroupProfitPerc < 0) {
                $("#HotelProfitPers").addClass('SumControls10Size');
            }
            else {
                $("#HotelProfitPers").addClass('SumControls10Sizeblack');
            }
            $("#HotelProfitPersCAD").text(GroupProfitPercCad.toFixed(2).toString() + " %")
            if (GroupProfitPercCad < 0) {
                $("#HotelProfitPersCAD").addClass('SumControls10Size');
            }
            else {
                $("#HotelProfitPersCAD").addClass('SumControls10Sizeblack');
            }
        }
    }
}
function HotelGridAjaxCompleted()
{
    if ($("#LeftScrollPossition").val() != "") {
        $("#OperHotelGrid").scrollLeft(parseFloat($("#LeftScrollPossition").val()));
    }
    if ($("#TopScrollPossition").val() != "") {
        $("#OperHotelGrid").scrollTop(parseFloat($("#TopScrollPossition").val()));
    }
    InitHotelSearchCalendars();
    UpdateGrpProfits();
}
function LoadRoomGrid() {
    // Rooms
    $.ajax({
        url: urls["LoadOperationRoomsTab"],
        contentType: 'application/json; charset=utf-8',
        data: $('#OperRoomGridForm').serialize(),
        type: 'POST',
        success: function (data) {
            $("#tabRooms").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            //  $("#LoadingDiv").hide();
            // $("#Tabs").show();
        }
    });
}
function LoadHotelGridByGroupCode(GroupCode) {
    // Hotel
    $.ajax({
        url: urls["LoadOperationHotelTabByGroup"],
        data: { 'GroupCode': GroupCode },
        type: 'POST',
        success: function (data) {
            $("#tabHotels").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            //  $("#LoadingDiv").hide();
            InitHotelSearchCalendars();
            IsHotelCompleted = true;
            UpdateGrpProfits();
        }
    });
}
function LoadRoomGridByGroupCode(GroupCode) {
    // Rooms
    $.ajax({
        url: urls["LoadOperationRoomsTabByGroup"],
        data: { 'GroupCode': GroupCode },
        type: 'POST',
        success: function (data) {
            $("#tabRooms").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            //  $("#LoadingDiv").hide();
             $("#Rooms").click();
        }
    });
}
function LoadAttractionsGrid() {
    // Attraction
    $.ajax({
        url: urls["LoadOperationAttractionsTab"],
        contentType: 'application/json; charset=utf-8',
        data: $('#OperAttractionsGridForm').serialize(),
        type: 'POST',
        success: function (data) {
            $("#tabAttractions").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            InitAttractionsSearchCalendars();
        }
    });
}
function LoadAttractionsGridByGroupCode(GroupCode) {
    // Attractions
    $.ajax({
        url: urls["LoadOperationAttractionsTabByGroup"],
        data: { 'GroupCode': GroupCode },
        type: 'POST',
        success: function (data) {
            $("#tabAttractions").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            InitAttractionsSearchCalendars();
            IsAttractionsCompleted = true;
            UpdateGrpProfits();
        }
    });
}

function LoadMiscGrid() {HotelPageNum
    // Misc
    $.ajax({
        url: urls["LoadOperationMiscTab"],
        contentType: 'application/json; charset=utf-8',
        data: $('#OperMiscGridForm').serialize(),
        type: 'POST',
        success: function (data) {
            $("#tabMisc").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            InitMiscSearchCalendars();
        }
    });
}
function LoadMiscGridByGroupCode(GroupCode) {
    // Attractions
    $.ajax({
        url: urls["LoadOperationMiscTabByGroup"],
        data: { 'GroupCode': GroupCode },
        type: 'POST',
        success: function (data) {
            $("#tabMisc").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            InitMiscSearchCalendars();
            IsMiscCompleted = true;
            UpdateGrpProfits();
        }
    });
}
function LoadBusGrid() {
    // Bus
    $.ajax({
        url: urls["LoadOperationBusTab"],
        contentType: 'application/json; charset=utf-8',
        data: $('#OperRoomGridForm').serialize(),
        type: 'POST',
        success: function (data) {
            $("#tabBus").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            //  $("#LoadingDiv").hide();
            // $("#Tabs").show();
            InitBusSearchCalendars();
        }
    });
}
function LoadTechProgGridByGroupCode(GroupCode) {
    // Tech Prog
    $.ajax({
        url: urls["LoadOperationTechProgTabByGroup"],
        data: { 'GroupCode': GroupCode },
        type: 'POST',
        success: function (data) {
            $("#tabTechProg").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
        }
    });
}
function LoadBusGridByGroupCode(GroupCode) {
    // Bus
    $.ajax({
        url: urls["LoadOperationBusTabByGroup"],
        data: { 'GroupCode': GroupCode },
        type: 'POST',
        success: function (data) {
            $("#tabBus").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            InitBusSearchCalendars();
            IsBusCompleted = true;
            UpdateGrpProfits();
        }
    });
}
function LoadGroupCheckListGridByGroupCode(GroupCode) {
    // Tech Prog
    $.ajax({
        url: urls["LoadOperationGroupCheckListTabByGroup"],
        data: { 'GroupCode': GroupCode },
        type: 'POST',
        success: function (data) {
            $("#tabGroupCheckList").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
        }
    });
}
function LoadGroupCheckListGrid() {
    // Group CheckList
    $.ajax({
        url: urls["LoadOperationGroupCheckListTab"],
        contentType: 'application/json; charset=utf-8',
        data: $('#OperRoomGridForm').serialize(),
        type: 'POST',
        success: function (data) {
            $("#tabGroupCheckList").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
        }
    });
}
function LoadTechProgGrid() {
    // Tech Prog
    var OperationTechProgGridViewModel = {
        TechProgIsSearch: false,
    }
    var DTO = JSON.stringify(OperationTechProgGridViewModel);
    $.ajax({
        url: urls["LoadOperationTechProgTab"],
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: DTO,
        success: function (data) {
            $("#tabTechProg").html(data);
        },
        error: function (xhr) {
            //   alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            
        }
    });   
}

function LoadInvoice() {
    // Invoice
    $.ajax({
        url: urls["LoadOperationInvoiceTab"],
        contentType: 'application/json; charset=utf-8',
        data: $('#OperRoomGridForm').serialize(),
        type: 'POST',
        success: function (data) {
            $("#tabInvoice").html(data);
        },
        error: function (xhr) {
            alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            InitInvoiceCalendars();
            //  $("#LoadingDiv").hide();
            // $("#Tabs").show();
        }
    });
}
// Filtering Room
$(document).on('click', '.RoomGridFilterBtn', function () {
    debugger;
    var ElemId = $(this).attr("id");
    var parDiv = $(this).parent().parent().parent();
    var width = parDiv.width();
    var position = parDiv.offset();
    position.top = position.top + parDiv.height() + 2;
    $("#" + ElemId + "MainDiv").offset({ top: position.top, left: position.left });
    $("#" + ElemId + "MainDiv").width(width - 3);
    if ($("#" + ElemId + "MainDiv").is(":visible")) {
        $("#" + ElemId + "MainDiv").hide();
        $("#IsRoomFilter").val("True");
        $("#RoomGridUpdate").click();
    }
    else
        $("#" + ElemId + "MainDiv").show();
});

// hide Room filter div when clicked on div 
$(document).on('click', '.RoomGridFilterDivClose', function () {
    $(this).parent().offset({ left: 0, top: 0 }).css({
        'display': 'none'
    });
});
function RoomGridAjaxCompleted() {
    if (UpdateConfirms == true) {
        LoadHotelGridByGroupCode($("#RoomGroupCodeTxt").val());
        LoadAttractionsGridByGroupCode($("#RoomGroupCodeTxt").val());
        LoadMiscGridByGroupCode($("#RoomGroupCodeTxt").val());
        LoadBusGridByGroupCode($("#RoomGroupCodeTxt").val());
        UpdateConfirms = false;
    }
}
// text element complete text 
$(document).on('input', '.TxtComplete', function () {
    if (RoomTimerId == null) {
        RoomAutoComElem = $(this).attr('id');
        RoomAutoComElemVal = $("#" + RoomAutoComElem).val();
        RoomTimerId = setInterval(function () {

            var keyword = $("#" + RoomAutoComElem).val();
            if (keyword == RoomAutoComElemVal) {
                var PropName = "";
                var tab = "";
                var IsRoomSearch = false;
                if (RoomAutoComElem == "RoomGroupNameTxt") {
                    PropName = "GroupName";
                    IsRoomSearch = true;
                    tab = "Room";
                }
                if (RoomAutoComElem == "InvGroupName") {
                    PropName = "GroupName";
                    IsRoomSearch = true;
                    tab = "Invoice";
                }
                if (RoomAutoComElem == "RoomGroupCodeTxt") {
                    PropName = "GroupCode";
                    IsRoomSearch = true;
                    tab = "Room";
                }
                if (RoomAutoComElem == "InvGroupCode") {
                    PropName = "GroupCode";
                    IsRoomSearch = true;
                    tab = "Invoice";
                }
                if (RoomAutoComElem.indexOf("RoomCustomer") != -1) {
                    PropName = "CustomerOrgName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "SearchCustomer") {
                    PropName = "CustomerOrgName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "SearchGroupName") {
                    PropName = "GroupName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "SearchGroupCode") {
                    PropName = "GroupCode";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "SearchVendorName") {
                    PropName = "VendorName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "TechProgSearchGroupCode") {
                    PropName = "GroupCode";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "RoomCustomerTxt") {
                    PropName = "Customer";
                    IsRoomSearch = true;
                    tab = "Room";
                }
                if (RoomAutoComElem == "BusSearchGroupCode") {
                    PropName = "GroupCode";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "BusSearchGroupName") {
                    PropName = "GroupName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "BusSearchCustomer") {
                    PropName = "CustomerOrgName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "BusSearchVendorName") {
                    PropName = "BusName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "AttractionsSearchGroupCode") {
                    PropName = "GroupCode";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "AttractionsSearchGroupName") {
                    PropName = "GroupName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "AttractionsSearchCustomer") {
                    PropName = "CustomerOrgName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "AttractionsSearchVendorName") {
                    PropName = "AttrRestName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "AttractionsSearchEmployee" || RoomAutoComElem == "SearchEmployee" || RoomAutoComElem == "MiscSearchEmployee" || RoomAutoComElem == "BusSearchEmployee") {
                    PropName = "OperEmployee";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "MiscSearchGroupCode") {
                    PropName = "GroupCode";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "OperGroupCode") {
                    PropName = "GroupCode";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "MiscSearchGroupName") {
                    PropName = "GroupName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "MiscSearchCustomer") {
                    PropName = "CustomerOrgName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "MiscSearchVendorName") {
                    PropName = "MiscName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "GroupCheckListSearchGroupCode") {
                    PropName = "GroupCode";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "GroupCheckListSearchGroupName") {
                    PropName = "GroupName";
                    IsRoomSearch = false;
                }
                if (RoomAutoComElem == "GroupCheckListSearchCustomer") {
                    PropName = "CustomerOrgName";
                    IsRoomSearch = false;
                }
                var position = $("#" + RoomAutoComElem).offset();
                position.top = position.top + $("#" + RoomAutoComElem).height()+5;
                if (IsRoomSearch) {
                    $.ajax({
                        url: urls["OperationRoomSearchComplete"],
                        data: { 'PropName': PropName, 'keyword': keyword, 'tab':tab },
                        type: 'POST',
                        success: function (data) {
                            $("#AutoCompleteDiv").html(data);
                            var width = $("#" + RoomAutoComElem).css("width");
                            $("#AutoCompleteDiv").css("width", width);
                            $("#AutoCompleteDiv").show();
                            $("#AutoCompleteDiv").offset(position);
                        },
                        error: function (xhr) {
                            //  alert('Error: ' + xhr.statusText);
                        },
                        complete: function () {
                            clearInterval(RoomTimerId);
                            RoomTimerId = null;
                        }
                    });
                }
                else
                {
                    $.ajax({
                        url: urls["RoomAutoComplete"],
                        data: { 'PropName': PropName, 'keyword': keyword },
                        type: 'POST',
                        success: function (data) {
                            $("#AutoCompleteDiv").html(data);
                            var width = $("#" + RoomAutoComElem).css("width");
                            $("#AutoCompleteDiv").css("width", width);
                            $("#AutoCompleteDiv").show();
                            $("#AutoCompleteDiv").offset(position);
                        },
                        error: function (xhr) {
                            //  alert('Error: ' + xhr.statusText);
                        },
                        complete: function () {
                            clearInterval(RoomTimerId);
                            RoomTimerId = null;
                        }
                    });
                }
            }
            else
                RoomAutoComElemVal = keyword;
        }, 600);
    }

});
$(document).on('click', '.AutoCompleteDivClose', function () {
    $(this).parent().parent().hide();
});
function htmlDecode(value) {
    return $('<div/>').html(value).text();
}
function RoomAutoCompleteRowClick(key, val)
{
    var val = htmlDecode(val)
    $("#" + RoomAutoComElem).val(val);
    if ($("#" + RoomAutoComElem).hasClass("Cust") || $("#" + RoomAutoComElem).hasClass("Emp"))
        $("#" + RoomAutoComElem).next().val(key);
    $("#AutoCompleteDiv").hide();
}
function RoomSearchCompleteRowClick(ControlName, GroupName, GroupCode, Customer, GroupId) {
    $("#RoomGroupNameTxt").val(GroupName);
    $("#RoomGroupCodeTxt").val(GroupCode);
    $("#RoomCustomerTxt").val(Customer);
    $("#RoomGroupIDTxt").val(GroupId);
    $("#AutoCompleteDiv").hide();
}
function InvoiceSearchCompleteRowClick(ControlName, GroupName, GroupCode, GroupId) {
    $("#InvGroupName").val(GroupName);
    $("#InvGroupCode").val(GroupCode);
    $("#InvGroupID").val(GroupId);
    $("#AutoCompleteDiv").hide();
    InitInvoiceCalendars();
}

$(document).on('click', '#RoomGridUpSearch', function () {
    if ($("#RoomGroupIDTxt").val() == "0") {
        jAlert("Can't Search, group is not selected...", 'Error!');
        return;
    }
    $("#IsRoomSearch").val("True");
    $("#RoomGridUpdate").click();
    
});

// Is Gir
$(document).on('click', '#IsGir', function () {
    if ($("#IsGir").is(":checked"))
    {
        $(".Cust").each(function (index, elem) {
            $(elem).prop("readonly", false);
        });
        $("#OperationRoomGirDiv").show();
    }
    else
    {
        $(".Cust").each(function (index, elem) {
            $(elem).prop("readonly", true);
        });
        $("#OperationRoomGirDiv").hide();
    }
});

// report master Rooming List
$(document).on('click', '#RoomingListReportBtn', function () {
    var VendorId = 0;
    window.open("../Report/RoomingListReport?GroupID=" + $("#RoomGroupIDTxt").val() + "&VendorID=" + VendorId);
});

// report each hotel rooming list
function OperVendorHotelPrev(VendorId, ArrivalDate)
{
    window.open("../Report/RoomingListReport?GroupID=" + $("#RoomGroupIDTxt").val() + "&VendorID=" + VendorId + "&ArrivalDate=" + ArrivalDate);
}

// report group vendor list
$(document).on('click', '#GVendorListReportBtn', function () {
    window.open("../Report/GroupVendorListReport?GroupID=" + $("#RoomGroupIDTxt").val());
});
// reports Authorization Form
$(document).on('click', '#AmexVendorReportBtn', function () {
    if ($("#AmexVendorID").val() > 0) {
        if ($('#OperationAmexVendorDetailsSaveBtn').hasClass('QuotaDetDataChanged')) {
            jConfirm(Messages["ChangePage"], Messages["ChangePageTitle"], function (retVal) {
                if (retVal == true) {
                    window.open("../Report/AuthorizationFormReport?AuthFormID=" + parseInt($("#AmexVendorID").val()), '_blank');
                }
            });
        }
        else {
            window.open("../Report/AuthorizationFormReport?AuthFormID=" + $("#AmexVendorID").val(), '_blank');
        }
    }
    else
    {
        jAlert(Messages["CreateReport"], Messages["CreateReportTitle"]);
    }
});
// Load Vendor Confirmation only
function OperGroupVendorConfLoad(GroupID, VendorID, ArrivalDate)
{
    $.ajax({
        url: urls["OperationLoadConfirmation"],
        data: { 'GroupID': GroupID, 'VendorID': VendorID, 'ArrivalDate': ArrivalDate },
        type: 'POST',
        success: function (data) {
            $("#tabConfirmation").html(data);
        },
        error: function (xhr) {
            //  alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            $("#VendorConfirm").click();
        }
    });
}
// Load Bus Confirmation only
function OperGroupBusConfLoad(GroupID, VendorID, ArrivalDate, VendorType) {
    $("#TabsVendorConfirm").hide();
    $("#TabsAttrBusConfirm").show();
    $.ajax({
        url: urls["OperationLoadAttrBusConfirmation"],
        data: { 'GroupID': GroupID, 'VendorID': VendorID, 'ArrivalDate': ArrivalDate, 'VendorType': VendorType },
        type: 'POST',
        success: function (data) {
            $("#TabsAttrBusConfirm").html(data);
        },
        error: function (xhr) {
            //  alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            $("#VendorConfirm").click();
        }
    });
}
// Load Attractions and Restaurants Confirmation only
function OperGroupAttractionsConfLoad(GroupID, VendorID, ArrivalDate, VendorType) {
    $("#TabsVendorConfirm").hide();
    $("#TabsAttrBusConfirm").show();
    $.ajax({
        url: urls["OperationLoadAttrBusConfirmation"],
        data: { 'GroupID': GroupID, 'VendorID': VendorID, 'ArrivalDate': ArrivalDate, 'VendorType': VendorType },
        type: 'POST',
        success: function (data) {
            $("#TabsAttrBusConfirm").html(data);
        },
        error: function (xhr) {
            //  alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            $("#VendorConfirm").click();
        }
    });
}
// Load Misc Confirmation only
function OperGroupMiscConfLoad(GroupID, VendorID, ArrivalDate, VendorType) {
    $("#TabsVendorConfirm").hide();
    $("#TabsAttrBusConfirm").show();
    $.ajax({
        url: urls["OperationLoadAttrBusConfirmation"],
        data: { 'GroupID': GroupID, 'VendorID': VendorID, 'ArrivalDate': ArrivalDate, 'VendorType': VendorType },
        type: 'POST',
        success: function (data) {
            $("#TabsAttrBusConfirm").html(data);
        },
        error: function (xhr) {
            //  alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            $("#VendorConfirm").click();
        }
    });
}
// Load Vendor Confirmation Room only
function OperGroupVendorConfRoomLoad(GroupID, VendorID) {
    $.ajax({
        url: urls["OperationLoadGroupVendorConfirmation"],
        data: { 'GroupID': GroupID, 'VendorID': VendorID },
        type: 'POST',
        success: function (data) {
            $("#tabRoomingList").html(data);
        },
        error: function (xhr) {
            //  alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            InitVendorConfirmCalendars();
        }
    });
}
// Load Vendor Confirmation from Hotel tab
function OperGroupVendorConf(GroupID, VendorID, ArrivalDate)
{
    $("#TabsAttrBusConfirm").hide();
    $("#TabsVendorConfirm").show();
    $.ajax({
        url: urls["OperationLoadConfirmation"],
        data: { 'GroupID': GroupID, 'VendorID': VendorID, 'ArrivalDate': ArrivalDate },
        type: 'POST',
        success: function (data) {
            $("#tabConfirmation").html(data);
        },
        error: function (xhr) {
            //  alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            $("#VendorConfirm").click();
        }
    });
    $.ajax({
        url: urls["OperationLoadGroupVendorConfirmation"],
        data: { 'GroupID': GroupID, 'VendorID': VendorID },
        type: 'POST',
        success: function (data) {
            $("#tabRoomingList").html(data);
        },
        error: function (xhr) {
            //  alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            InitVendorConfirmCalendars();
        }
    });
}

// open Vendor Conf
function OperGroupVendorLoad(VendorID, ArrivalDate)
{
    $.ajax({
        url: urls["OperationLoadGroupVendorConfirmation"],
        data: { 'GroupID': $("#RoomGroupIDTxt").val(), 'VendorID': VendorID },
        type: 'POST',
        success: function (data) {
            $("#tabRoomingList").html(data);

        },
        error: function (xhr) {
            //  alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            InitVendorConfirmCalendars();
        }
    });
    $.ajax({
        url: urls["OperationLoadConfirmation"],
        data: { 'GroupID': $("#RoomGroupIDTxt").val(), 'VendorID': VendorID, 'ArrivalDate': ArrivalDate },
        type: 'POST',
        success: function (data) {
            $("#tabConfirmation").html(data);
        },
        error: function (xhr) {
            //  alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            InitVendorConfirmCalendars();
        }
    });
    $("#VendorConfirm").click();
}

// portrege flag checked
$(document).on('click', '#PorterageFlag', function () {
    if ($("#PorterageFlag").is(":checked"))
        $("#GVendorPorterDiv").show();
    else
        $("#GVendorPorterDiv").hide();
});

// init vendor confirmation calendars
function InitVendorConfirmCalendars()
{
    $(".VendConfCalendar").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 999999
            });
        }
    });
}
// init Invoice calendars
function InitInvoiceCalendars() {
    $(".InvoiceDateCalendar").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 999999
            });
        }
    });
}

// Invoice Tab

$(document).on('click', '#InvoiceSearch', function () {
    if ($("#InvGroupID").val() == "0") {
        jAlert("Can't Search, group is not selected...", 'Error!');
        return;
    }
    $("#IsInvSearch").val("True");
    $("#InvoiceSave").click();
});

 // Amex Form
function InitOperationAmexVendorDetailsDataCalendars() {

    $(".OperationAmexVendorDetails").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 999999
            });
        }
    });
}
function ShowOperationAttractionsOptionalDetails(GroupID, VendorID, ArrivalDate, Category) {
    var Instance = $('#OperAttractionsGrid').data('handsontable');
    var row = 0;
    var VendorTypeName = "";
    $(Instance.getData()).each(function (index, elem) {
        if (elem.AttractionsVendorID == VendorID && elem.AttractionsGroupID == GroupID && Date.parse(elem.AttractionsDate) == Date.parse(ArrivalDate) && elem.AttractionsType == Category) {
            VendorTypeName = elem.AttractionsCategory
            row = index;
        }
    });
    $.ajax({
        url: urls["OperationLoadOptionalDetails"],
        data: { 'VendorID': VendorID },
        type: 'GET',
        success: function (data) {
            $("#OperationOptionalDetailsDiv").html(data);
        },
        error: function (xhr) {
            //  alert('Error: ' + xhr.statusText);
        },
        complete: function () {
            if ($("#OperationOptionalDetailsDiv .OptionalIDForCheck").length > 0) {
                ShowOperationAttractionsOptionalDetailPopUp("OperationOptionalDetailsDiv", Instance, row);
                AttractionsisSelectOperationOptionalDetails = false;
            }
            else {
                $("#OperationOptionalDetailsDiv").empty();
                jAlert("No any optional for this " + VendorTypeName, "Warning!")
            }
        }
    });
}
function ShowOperationAttractionsOptionalDetailPopUp(PopUpDiv, Instance, row) {
    $.colorbox({
        width: "800px",
        height: "600px",
        inline: true,
        href: "#" + PopUpDiv,
        onComplete: function () {
            $("#" + PopUpDiv).show();
        },
        onClosed: function () {
            $("#" + PopUpDiv).hide();
            if (AttractionsisSelectOperationOptionalDetails) {
                AttractionsUpdateFormPropOptional(Instance, row, AttractionsisOperationOptionalDetailsPrice);
                AttractionsisSelectOperationOptionalDetails = false;
            }
        }
    });
}
function SelectOptionalPrice(Price) {
    AttractionsisOperationOptionalDetailsPrice = parseInt(Price);
    AttractionsisSelectOperationOptionalDetails = true;
    $("#OperationOptionalDetailsDiv").empty();
    $.colorbox.close();
}
function ShowOperationAmexVendorDetails(GroupID, VendorID, LineNo, ArrivalDate, OperationTabName, Category) {
    var Instance = $('#OperHotelGrid').data('handsontable');
    var row = 0;
    $(Instance.getData()).each(function (index, elem) {
        if (elem.VendorID == VendorID && elem.GroupID == GroupID && Date.parse(elem.ArrivalDate) == Date.parse(ArrivalDate)) {
            row = index;
        }
    });
    var PayMethod = "";
    if (LineNo == 1)
        PayMethod = Instance.getData()[row].FirstPaymentMethod;
    if (LineNo == 2)
        PayMethod = Instance.getData()[row].SecondPaymentMethod;
    if (LineNo == 3)
        PayMethod = Instance.getData()[row].ThirdPaymentMethod;
    var CardID = 0;
    $(HotelModel[0].PaymentMethod).each(function (index, elem) {
        if (elem.Text == PayMethod)
            CardID = elem.Value;
    });
    if (CardID == 0) {
        if (LineNo == 1)
            jAlert("Please Choose " + OperationTabName + " First Payment Method", "Warning!")
        if (LineNo == 2)
            jAlert("Please Choose " + OperationTabName + " Second Payment Method", "Warning!")
        if (LineNo == 3)
            jAlert("Please Choose " + OperationTabName + " Third Payment Method", "Warning!")
    }
    else {
        $.ajax({
            url: urls["OperationLoadOperationAmexVendors"],
            data: { 'VendorID': VendorID, 'GroupID': GroupID, 'CardID': CardID, 'LineNo': LineNo, 'ArrivalDate': ArrivalDate, 'OperationTabName': OperationTabName, 'Category': Category, 'Time': "" },
            type: 'GET',
            success: function (data) {
                $("#OperationAmexVendorDetailsDiv").html(data);
            },
            error: function (xhr) {
                //  alert('Error: ' + xhr.statusText);
            },
            complete: function () {
                ShowOperationAmexVendorDetailPopUp("OperationAmexVendorDetailsDiv", LineNo, VendorID, Instance, row);
                InitOperationAmexVendorDetailsDataCalendars();
                isSaveOperationAmex = false;
            }
        });
    }
}
function ShowOperationAmexVendorDetailPopUp(PopUpDiv, LineNo, VendorID, Instance, row) {
    $.colorbox({
        width: "1050px",
        height: "830px",
        inline: true,
        href: "#" + PopUpDiv,
        onComplete: function () {
            $("#" + PopUpDiv).show();
        },
        onClosed: function () {
            $("#" + PopUpDiv).hide();
            if (isSaveOperationAmex) {
                UpdateFormProp(LineNo, VendorID, Instance, row);
                isSaveOperationAmex = false;
            }
        }
    });
}
function ShowOperationAttractionsAmexVendorDetails(GroupID, VendorID, LineNo, ArrivalDate, OperationTabName, Category) {
    var Instance = $('#OperAttractionsGrid').data('handsontable');
    var row = 0;
    $(Instance.getData()).each(function (index, elem) {
        if (elem.AttractionsVendorID == VendorID && elem.AttractionsGroupID == GroupID && Date.parse(elem.AttractionsDate) == Date.parse(ArrivalDate) && elem.AttractionsType == Category) {
            row = index;
        }
    });
    var PayMethod = "";
    if (LineNo == 1)
        PayMethod = Instance.getData()[row].AttractionsSelectedFirstPaymentMethod;
    if (LineNo == 2)
        PayMethod = Instance.getData()[row].AttractionsSelectedSecondPaymentMethod;
    if (LineNo == 3)
        PayMethod = Instance.getData()[row].AttractionsSelectedThirdPaymentMethod;
    var CardID = 0;
    $(AttractionsModel[0].PaymentMethod).each(function (index, elem) {
        if (elem.Text == PayMethod)
            CardID = elem.Value;
    });
    var Time = Instance.getData()[row].AttractionsTime;
    var JalertVendorType = "";
    if (OperationTabName == "Restaurants")
        JalertVendorType = "Restaurant";
    else
        JalertVendorType = "Attraction";
    if (CardID == 0) {
        if (LineNo == 1)
            jAlert("Please Choose " + JalertVendorType + " First Payment Method", "Warning!")
        if (LineNo == 2)
            jAlert("Please Choose " + JalertVendorType + " Second Payment Method", "Warning!")
        if (LineNo == 3)
            jAlert("Please Choose " + JalertVendorType + " Third Payment Method", "Warning!")
    }
    else if (Time == null || Time == "")
        jAlert("Please select time for this " + JalertVendorType, "Warning!")
    else {
        $.ajax({
            url: urls["OperationLoadOperationAmexVendors"],
            data: { 'VendorID': VendorID, 'GroupID': GroupID, 'CardID': CardID, 'LineNo': LineNo, 'ArrivalDate': ArrivalDate, 'OperationTabName': OperationTabName, 'Category': Category, 'Time': Time },
            type: 'GET',
            success: function (data) {
                $("#OperationAttractionsAmexVendorDetailsDiv").html(data);
            },
            error: function (xhr) {
                //  alert('Error: ' + xhr.statusText);
            },
            complete: function () {
                ShowOperationAttractionsAmexVendorDetailPopUp("OperationAttractionsAmexVendorDetailsDiv", LineNo, VendorID, Instance, row);
                InitOperationAmexVendorDetailsDataCalendars();
                AttractionsisSaveOperationAmex = false;
            }
        });
    }
}
function ShowOperationAttractionsAmexVendorDetailPopUp(PopUpDiv, LineNo, VendorID, Instance, row) {
    $.colorbox({
        width: "1050px",
        height: "830px",
        inline: true,
        href: "#" + PopUpDiv,
        onComplete: function () {
            $("#" + PopUpDiv).show();
        },
        onClosed: function () {
            $("#" + PopUpDiv).hide();
            if (AttractionsisSaveOperationAmex) {
                AttractionsUpdateFormProp(LineNo, VendorID, Instance, row);
                AttractionsisSaveOperationAmex = false;
            }
        }
    });
}
function ShowOperationMiscAmexVendorDetails(GroupID, VendorID, LineNo, ArrivalDate, OperationTabName, Category) {
    var Instance = $('#OperMiscGrid').data('handsontable');
    var row = 0;
    $(Instance.getData()).each(function (index, elem) {
        if (elem.MiscVendorID == VendorID && elem.MiscGroupID == GroupID && Date.parse(elem.MiscStartDate) == Date.parse(ArrivalDate)) {
            row = index;
        }
    });
    var PayMethod = "";
    if (LineNo == 1)
        PayMethod = Instance.getData()[row].MiscSelectedFirstPaymentMethod;
    if (LineNo == 2)
        PayMethod = Instance.getData()[row].MiscSelectedSecondPaymentMethod;
    if (LineNo == 3)
        PayMethod = Instance.getData()[row].MiscSelectedThirdPaymentMethod;
    var CardID = 0;
    $(MiscModel[0].PaymentMethod).each(function (index, elem) {
        if (elem.Text == PayMethod)
            CardID = elem.Value;
    });
    var Time = Instance.getData()[row].MiscTime;
    if (CardID == 0) {
        if (LineNo == 1)
            jAlert("Please Choose " + OperationTabName + " First Payment Method", "Warning!")
        if (LineNo == 2)
            jAlert("Please Choose " + OperationTabName + " Second Payment Method", "Warning!")
        if (LineNo == 3)
            jAlert("Please Choose " + OperationTabName + " Third Payment Method", "Warning!")
    }
    else {
        $.ajax({
            url: urls["OperationLoadOperationAmexVendors"],
            data: { 'VendorID': VendorID, 'GroupID': GroupID, 'CardID': CardID, 'LineNo': LineNo, 'ArrivalDate': ArrivalDate, 'OperationTabName': OperationTabName, 'Category': Category, 'Time': Time },
            type: 'GET',
            success: function (data) {
                $("#OperationAmexVendorDetailsDiv").html(data);
            },
            error: function (xhr) {
                //  alert('Error: ' + xhr.statusText);
            },
            complete: function () {
                ShowOperationMiscAmexVendorDetailPopUp("OperationAmexVendorDetailsDiv", LineNo, VendorID, Instance, row);
                InitOperationAmexVendorDetailsDataCalendars();
                MiscisSaveOperationAmex = false;
            }
        });
    }
}
function ShowOperationMiscAmexVendorDetailPopUp(PopUpDiv, LineNo, VendorID, Instance, row) {
    $.colorbox({
        width: "1050px",
        height: "830px",
        inline: true,
        href: "#" + PopUpDiv,
        onComplete: function () {
            $("#" + PopUpDiv).show();
        },
        onClosed: function () {
            $("#" + PopUpDiv).hide();
            if (MiscisSaveOperationAmex) {
                MiscUpdateFormProp(LineNo, VendorID, Instance, row);
                MiscisSaveOperationAmex = false;
            }
        }
    });
}
function ShowOperationBusAmexVendorDetails(GroupID, VendorID, LineNo, ArrivalDate, OperationTabName, Category) {
    var Instance = $('#OperBusGrid').data('handsontable');
    var row = 0;
    $(Instance.getData()).each(function (index, elem) {
        if (OperationTabName != "Guide") {
            if (elem.BusVendorID == VendorID && elem.BusGroupID == GroupID && Date.parse(elem.BusStart) == Date.parse(ArrivalDate)) {
                row = index;
            }
        }
        else
        {
            if (elem.BusGuideID == VendorID && elem.BusGroupID == GroupID && Date.parse(elem.BusStart) == Date.parse(ArrivalDate)) {
                row = index;
            }
        }
    });
    var PayMethod = "";
    if (OperationTabName != "Guide") {
        if (LineNo == 1)
            PayMethod = Instance.getData()[row].BusSelectedFirstPaymentMethod;
        if (LineNo == 2)
            PayMethod = Instance.getData()[row].BusSelectedSecondPaymentMethod;
        if (LineNo == 3)
            PayMethod = Instance.getData()[row].BusSelectedThirdPaymentMethod;
    }
    else
    {
        if (LineNo == 1)
            PayMethod = Instance.getData()[row].BusGuideSelectedFirstPaymentMethod;
        if (LineNo == 2)
            PayMethod = Instance.getData()[row].BusGuideSelectedSecondPaymentMethod;
        if (LineNo == 3)
            PayMethod = Instance.getData()[row].BusGuideSelectedThirdPaymentMethod;
    }
    var CardID = 0;
    var Time = Instance.getData()[row].BusTime;
    $(BusModel[0].PaymentMethod).each(function (index, elem) {
        if (elem.Text == PayMethod)
            CardID = elem.Value;
    });
    if (CardID == 0) {
        if (LineNo == 1)
            jAlert("Please Choose " + OperationTabName + " First Payment Method", "Warning!")
        if (LineNo == 2)
            jAlert("Please Choose " + OperationTabName + " Second Payment Method", "Warning!")
        if (LineNo == 3)
            jAlert("Please Choose " + OperationTabName + " Third Payment Method", "Warning!")
    }
    else if(Time == null || Time =="")
        jAlert("Please select time for this " + OperationTabName, "Warning!")
    else {
        $.ajax({
            url: urls["OperationLoadOperationAmexVendors"],
            data: { 'VendorID': VendorID, 'GroupID': GroupID, 'CardID': CardID, 'LineNo': LineNo, 'ArrivalDate': ArrivalDate, 'OperationTabName': OperationTabName, 'Category': Category, 'Time': Time},
            type: 'GET',
            success: function (data) {
                $("#OperationBusAmexVendorDetailsDiv").html(data);
            },
            error: function (xhr) {
                //  alert('Error: ' + xhr.statusText);
            },
            complete: function () {
                ShowOperationBusAmexVendorDetailPopUp("OperationBusAmexVendorDetailsDiv", LineNo, VendorID, Instance, row, Category);
                InitOperationAmexVendorDetailsDataCalendars();
                BusisSaveOperationAmex = false;
            }
        });
    }
}
function ShowOperationBusAmexVendorDetailPopUp(PopUpDiv, LineNo, VendorID, Instance, row, Category) {
    $.colorbox({
        width: "1050px",
        height: "830px",
        inline: true,
        href: "#" + PopUpDiv,
        onComplete: function () {
            $("#" + PopUpDiv).show();
        },
        onClosed: function () {
            $("#" + PopUpDiv).hide();
            if (BusisSaveOperationAmex) {
                BusUpdateFormProp(LineNo, VendorID, Instance, row, Category);
                BusisSaveOperationAmex = false;
            }
        }
    });
}
$(document).on('click', '#OperationAmexVendorDetailsSaveBtn', function () {
    var $form = $("#LoadAmexVendorDetailsForm");
    $form.validate();
    if ($form.valid()) {
        OperationClientSideHide = false;
        var OperationAmexVendorViewModel = {
            AmexVendorID: $("#AmexVendorID").val(),
            GroupID: $("#GroupID").val(),
            VendorID: $("#VendorID").val(),
            OperationTabName: $("#OperationTabName").val(),
            OperAmexVndArrivalDate: $("#OperAmexVndArrivalDate").val(),
            AmexRestCategory: $("#AmexRestCategory").val(),
            LineNo: $("#LineNo").val(),
            CardID: $("#CardID").val(),
            Date: $("#Date").val(),
            PreparedBy: $("#PreparedBy").val(),
            Attention: $("#Attention").val(),
            ExpectedCommissionAmount: $("#ExpectedCommissionAmount").val(),
            CommissionableAmount: $("#CommissionableAmount").val(),
            CommissionAmountReceived: $("#CommissionAmountReceived").val(),
            CommissionReceivedDate: $("#CommissionReceivedDate").val(),
            AuthorizedAmount: $("#AuthorizedAmount").val(),
            Charged: $("#Charged").prop('checked'),
            IsItCommissionable: $("#IsItCommissionable").prop('checked'),
            PaymentFor: $("#PaymentFor").val(),
            SelectedCurrency: $("#SelectedCurrency").val(),
        };
        var DTO = JSON.stringify(OperationAmexVendorViewModel);
        console.log(DTO);
        $.ajax({
            url: urls["OperationSaveOperationAmexVendors"],
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: DTO,
            success: function (data) {
                if (data.indexOf("Error") != -1)
                    jAlert(data, "Error");
            },
            error: function (xhr) {
                jAlert(xhr.statusText,"Error");
            },
            complete: function () {
                $('#OperationAmexVendorDetailsSaveBtn').removeClass('QuotaDetDataChanged');
                switch($("#OperationTabName").val())
                {
                    case "Hotel":
                        isSaveOperationAmex = true;
                        break;
                    case "Attractions":
                        AttractionsisSaveOperationAmex = true;
                        break;
                    case "Restaurants":
                        AttractionsisSaveOperationAmex = true;
                        break;
                    case "Misc":
                        MiscisSaveOperationAmex = true;
                        break;
                    case "Bus":
                        BusisSaveOperationAmex = true;
                        break;
                    case "Guide":
                        BusisSaveOperationAmex = true;
                        break;
                    default:
                        break;
                }
                $('#cboxClose').click();
            }
        });
    }
    else
    {
        OperationClientSideHide = true;
    }
});
function ShowOperationVendorContractDetails(FilePath) {
    if (FilePath != null && FilePath.length > 0) {
        $.colorbox({
            iframe: true,
            innerWidth: 1100,
            innerHeight: 700,
            // href: "/VendorContracts/4/14/P1020276.JPG",
            href: FilePath,
        });
    }
    else
        jAlert("No contract to show!","Warning!");
}
$(document).on('click', '#StartUpload', function () {
    var data = new FormData();
    var files = $('#UploadVendorConfirmFilePath').get(0).files;

    if ($(files).length > 0) {
        data.append('UploadedFiles', files[0]);
        $.ajax({
            type: 'POST',
            url: '/Operation/UploadVendorConfirmFile?VendorID=' + $("#ConfVendorID").val() + '&GroupID=' + $("#ConfGroupID").val() + '&VendorType=' + $("#VendorType").val() + '&UpdateAll=' + false,
            data: data,
            dataType: 'json', // have tried this ajax without dataType, same problem
            contentType: false,
            processData: false,
            success: function (data) {
                jAlert(data.message, "Successful!");
                $("#StartUpload").removeClass('QuotaDetDataChanged');
            },
            error: function (param1, param2, param3) {
                jAlert("error", 'Error!');
            },
            complete: function () {
                OperGroupVendorConfLoad($("#ConfGroupID").val(), $("#ConfVendorID").val(), $("#ConfArrivalDate").val());
                LoadHotelGridByGroupCode($("#ConfGroupCode").val());
            }
        });
    }
    else
        jAlert("Please Choose File For Upload",'Warning!');
  
});
$(document).on('click', '#Download', function () {
    window.open('../Operation/DownloadVendorConfirmFile?FileName=' + $("#VendorConfirmFileHidden").val())
});
$(document).on('change', '#UploadVendorConfirmFilePath', function () {
    $("#DownloadDiv").hide();
    $("#StartUpload").addClass('QuotaDetDataChanged');
});

$(document).on('click', '#AttrBusStartUpload', function () {
    var data = new FormData();
    var files = $('#UploadAttrBusConfirmFilePath').get(0).files;

    if ($(files).length > 0) {
        data.append('UploadedFiles', files[0]);
        $.ajax({
            type: 'POST',
            url: '/Operation/UploadVendorConfirmFile?VendorID=' + $("#AttrBusConfVendorID").val() + '&GroupID=' + $("#AttrBusConfGroupID").val() + '&VendorType=' + $("#AttrBusVendorType").val() + '&UpdateAll=' + $("#UpdateAllContracts").is(':checked'),
            data: data,
            dataType: 'json', // have tried this ajax without dataType, same problem
            contentType: false,
            processData: false,
            success: function (data) {
                jAlert(data.message, "Successful!");
                $("#AttrBusStartUpload").removeClass('QuotaDetDataChanged');
            },
            error: function (param1, param2, param3) {
                jAlert("error", 'Error!');
            },
            complete: function () {
                switch ($("#AttrBusVendorType").val()) {
                    case "Bus":
                        {
                            OperGroupBusConfLoad($("#AttrBusConfGroupID").val(), $("#AttrBusConfVendorID").val(), $("#AttrBusConfArrivalDate").val(), $("#AttrBusVendorType").val());
                            LoadBusGridByGroupCode($("#AttrBusConfGroupCode").val());
                        }
                        break;
                    case "Attractions":
                        {
                            OperGroupAttractionsConfLoad($("#AttrBusConfGroupID").val(), $("#AttrBusConfVendorID").val(), $("#AttrBusConfArrivalDate").val(), $("#AttrBusVendorType").val());
                            LoadAttractionsGridByGroupCode($("#AttrBusConfGroupCode").val());
                        }
                        break;
                    case "Restaurants":
                        {
                            OperGroupAttractionsConfLoad($("#AttrBusConfGroupID").val(), $("#AttrBusConfVendorID").val(), $("#AttrBusConfArrivalDate").val(), $("#AttrBusVendorType").val());
                            LoadAttractionsGridByGroupCode($("#AttrBusConfGroupCode").val());
                        }
                        break;
                    case "Misc":
                        {
                            OperGroupMiscConfLoad($("#AttrBusConfGroupID").val(), $("#AttrBusConfVendorID").val(), $("#AttrBusConfArrivalDate").val(), $("#AttrBusVendorType").val());
                            LoadMiscGridByGroupCode($("#AttrBusConfGroupCode").val());
                        }
                        break;
                    default:
                        {
                            OperGroupVendorConfLoad($("#AttrBusConfGroupID").val(), $("#AttrBusConfVendorID").val(), $("#AttrBusConfArrivalDate").val());
                            LoadHotelGridByGroupCode($("#AttrBusConfGroupCode").val());
                        }
                        break;
                }

            }
        });
    }
    else
        jAlert("Please Choose File For Upload", 'Warning!');

});
$(document).on('click', '#AttrBusDownload', function () {
    window.open('../Operation/DownloadVendorConfirmFile?FileName=' + $("#AttrBusConfirmFileHidden").val())
});
$(document).on('change', '#UploadAttrBusConfirmFilePath', function () {
    $("#AttrBusDownloadDiv").hide();
    $("#AttrBusStartUpload").addClass('QuotaDetDataChanged');
});
var originalClose = $.colorbox.close;
$.colorbox.close = function () {
    if ($('#OperationAmexVendorDetailsSaveBtn').hasClass('QuotaDetDataChanged')) {
        jConfirm(Messages["ClosePopUp"], Messages["ClosePopUpTitle"], function (retVal) {
            if (retVal == true) {
                $('#OperationAmexVendorDetailsSaveBtn').removeClass('QuotaDetDataChanged');
                OperationClientSideHide = false;
                originalClose();
            }
        });
    }
    else {
        OperationClientSideHide = false;
        originalClose();
    }
};
$(document).on('change', '.ElementsForValidation', function () {
    if ($(this).valid()) {
        $(this).closest("form").find("#errorMessageClient").text("");
    }
    else
        $(this).closest("form").find("#errorMessageServer").hide();
    if (OperationClientSideHide) {
        if ($(this).closest("form").valid()) {
            $(this).closest("form").find("#errorMessageClient").text("");
        }
    }
    else if ($(this).valid()) {
        var elements = "#" + $(this).closest("form").attr("id") + " .error";
        $(elements).not('label').each(function () {
            $(this).valid();
        });
    }
});
function ViewInvoiceProposal() {
        $.colorbox({
            iframe: true,
            innerWidth: 1100,
            innerHeight: 700,
            // href: "/VendorContracts/4/14/P1020276.JPG",
            href: $("#ProposalFIleHidden").val(),
        });
};
function OperMainGroupCodeClick()
{
    window.location = '../Operation/Operation?Roomtab=Y&GroupCode=' + $("#OperGroupCode").val();
    
}